package cn.caplike.demo.nio._2017;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;

/**
 * 简介：Sender
 *
 * @author 李珂 2017年11月23日 上午10:56:13
 */
public class DatagramChannelTestSender {
    public static void main(String[] args) {
        try {
            send();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void send() throws IOException {
        DatagramChannel channel = DatagramChannel.open();

//		ByteBuffer buffer = ByteBuffer.wrap("下雨的夜晚很安静".getBytes("utf-8"));

        ByteBuffer buffer = ByteBuffer.allocate(512);
        buffer.put("下雨的夜晚很安静".getBytes(StandardCharsets.UTF_8));
        buffer.flip();

        channel.send(buffer, new InetSocketAddress("localhost", 10022));
        channel.close();
    }
}
